import {
  AfterViewInit,
  ChangeDetectionStrategy,
  Component,
  ElementRef,
  Host,
  Input, OnDestroy,
  Optional, Renderer2,
  ViewEncapsulation
} from '@angular/core';
import { ApesColDirective, ApesRowDirective } from '@shared/apes/grid';
import { ApesUpdateHostClassService } from '@shared/apes/core/services/update-host-class.service';
import { ApesFormItemComponent } from '@shared/apes/form/apes-form-item.component';
import { InputBoolean } from '@shared/apes/core/util/convert';

@Component({
  selector           : 'apes-form-label',
  providers          : [ ApesUpdateHostClassService ],
  preserveWhitespaces: false,
  encapsulation      : ViewEncapsulation.None,
  changeDetection    : ChangeDetectionStrategy.OnPush,
  templateUrl        : './apes-form-label.component.html'
})
export class ApesFormLabelComponent extends ApesColDirective implements OnDestroy, AfterViewInit {
  @Input() apesFor: string;
  @Input() @InputBoolean() apesRequired = false;

  constructor(updateHostClassService: ApesUpdateHostClassService, elementRef: ElementRef, @Optional() @Host() apesFormItemComponent: ApesFormItemComponent, @Optional() @Host() apesRowDirective: ApesRowDirective, renderer: Renderer2) {
    super(updateHostClassService, elementRef, apesFormItemComponent || apesRowDirective, renderer);
    renderer.addClass(elementRef.nativeElement, 'apes-form-item-label');
  }

  ngOnDestroy(): void {
    super.ngOnDestroy();
  }

  ngAfterViewInit(): void {
    super.ngAfterViewInit();
  }
}
